package com.gxuwz.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.google.gson.Gson;
import com.gxuwz.core.model.Cols;
import com.gxuwz.core.model.Page;
import com.gxuwz.core.util.MainUtil;
import com.gxuwz.core.util.UidUtils;
import com.gxuwz.core.web.action.BaseAction;
import com.gxuwz.pojo.SysUser;
import com.gxuwz.service.IInfoService;
import com.gxuwz.service.ISysUserService;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;


public class SysUserAction extends BaseAction implements Preparable, ModelDriven<SysUser>{
	
	protected static final String LIST_JSP = "/WEB-INF/page/user/user_list.jsp";
	protected static final String EDIT_JSP = "/WEB-INF/page/user/user_edit.jsp"; 
	protected static final String ADD_JSP = "/WEB-INF/page/user/user_add.jsp"; 

	@Autowired
	private ISysUserService sysUserService;
	@Autowired
	private IInfoService infoService;
	
	
	private Page pageUtil;
	private SysUser sysUser;
	
	private String result;


	/**
	 * 模糊查询打开页面
	 */
	public void list(){
		pageUtil = new Page();
		pageUtil.setCode(0);
		pageUtil.setData(sysUserService.findByEntity(sysUser));
		pageUtil.setCount(pageUtil.getData().size());
		reJson(pageUtil);
	}
	
	/**
	 * 获得数据（下拉框）
	 */
	public void getList(){
		reJson(sysUserService.findByEntity(sysUser));
		return;
	}
	
	public void del(){
		sysUserService.remove(sysUser);
		return;
	}
	
	/**
	 * 添加用户
	 */
	public void add(){
		sysUser.setUserAcademy(infoService.findById(sysUser.getUserAcademyId()).getInfoName());
		sysUser.setUserMajor(infoService.findById(sysUser.getUserMajorId()).getInfoName());
		sysUser.setUserClass(infoService.findById(sysUser.getUserClassId()).getInfoName());
		sysUser.setUserUnit(infoService.findById(sysUser.getUserUnitId()).getInfoName());
		sysUserService.save(sysUser);
		
		return;
	}
	
	public void update(){
		sysUserService.update(sysUser);
		return;
	}
	

	
	public String toList(){
		setForwardView(LIST_JSP);
		return SUCCESS;
	}
	
	public String toAdd(){
		setForwardView(ADD_JSP);
		return SUCCESS;
	}
	
	public String toEdit(){
		sysUser = sysUserService.findById(sysUser.getId());
		setForwardView(EDIT_JSP);
		return SUCCESS;
	}

	public SysUser getSysUser() {
		return sysUser;
	}

	public void setSysUser(SysUser sysUser) {
		this.sysUser = sysUser;
	}

	@Override
	public SysUser getModel() {
		// TODO Auto-generated method stub
		return sysUser;
	}

	@Override
	public void prepare() throws Exception {
		// TODO Auto-generated method stub
		sysUser = new SysUser();
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	

	
	
	
}
